create proc dbo.p_ConnectionStillAlive( 
						@DatabaseID bigint,
						@Connect_SPID bigint,
						@Connect_HostName varchar(255),
						@Connect_LoginName varchar(255),
						@Connect_Status varchar(255),
						@Connect_BlockID bigint,
						@Connect_Command varchar(255)) as

declare @Src_ID bigint,
		@MostRecent_ID bigint

select
	@Src_ID=(select
		max(a.[ID])
	from
		connecthistory a
	where
		a.[databaseid]=@DatabaseID
		and a.[connect_spid]=@Connect_SPID                   
		and a.connect_hostname=@Connect_HostName
		and a.[connect_loginname]=@Connect_LoginName
		and a.[Connect_Status]=@Connect_Status
		and a.[Connect_BlockID]=@Connect_BlockID
		and a.[Connect_Command]=@Connect_Command)
,
	@MostRecent_ID=(select
		max(a.[ID])
	from
		connecthistory a
	where
		a.[databaseid]=@DatabaseID
		and a.[connect_spid]=@Connect_SPID)

if @Src_ID=@MostRecent_ID 
	select @Src_ID
else
	select null